<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加用户角色页面</title>
</head>
<%
	String path = request.getContextPath();
	request.setAttribute("path", request.getContextPath());
	request.setAttribute("jsPath", path + "/js");
%>
<style type="text/css">
	th{font-size:20px;padding:20px;}
	td{text-align:right;line-height:2em;}
form {
	width: 35%;
	margin: auto;
}
</style>
<script type="text/javascript" src="${jsPath}/jquery-1.8.3.min.js"></script>
<script>
$(function () {
    var msg = $("#msg").html();
    if (msg != null) {
        alert(msg);
    }
});
function sub() {
    var st = 0;
    $.ajax({
        type: 'post',
        url: '<%=path%>/userRole/addAjax',
        data: {
            'staffId': $('#staffId').val(),
            'roleId': $('#roleId').val()
        },
        dataType: 'json',
        success: function (data) {
            if (data == 1) {
                alert('没有这个用户');
            }
            if (data == 2) {
                alert('没有这个职位');
            }
            if (data == 0) {
                st = 1;
            }
        },
        error: function (error) {
            alert('数据库没有这个值');
        }
    });
    if (st == 0) {
    	console.log('fa');
        return true;
    } else {
    	console.log('tr');
        return false;
    }
}

</script>
<body>
	<c:if test="${not empty msg}">
		<p style="display: none" id="msg">${msg}</p>
	</c:if>
	<form action="${path}/userRole/add" method="post" id="form1"
		onsubmit="return sub()">
		<table>
			<tr>
				<th colspan="2">添加用户角色信息</th>
			</tr>
			<tr>
				<td>选择用户：</td>
				<td style="text-align:left;"><select name="staffId" id="staffId">
						<c:forEach items="${staffs}" var="sta">
							<option value="${sta.staffId}">${sta.chnName}</option>
						</c:forEach>
				</select> <!-- <input type="text" name="staffId" required /> --></td>
			</tr>
			<tr>
				<td>职位：</td>
				<td style="text-align:left;"><select name="roleId" id="roleId">
						<c:forEach items="${sysRoles}" var="sys">
							<option value="${sys.roleId}">${sys.name}</option>
						</c:forEach>
				</select></td>
			</tr>
			<tr>
				<td></td>
				<td style="text-align: left;"><input type="button" name="back"
					value="返回" onclick="javascript:history.back(-1);" /> <input
					type="submit" value="添加" /></td>
			</tr>
		</table>
	</form>
</body>
</html>